package test;

import java.util.List;

public class Allocator2 {

    private List<Object> als;

    synchronized void apply(Object from, Object to) {
        while (als.contains(from) || als.contains(to)) {
            try {
                wait();
            } catch (InterruptedException e) {

            }
            als.add(from);
            als.add(to);
        }
    }


    synchronized void free(Object from, Object to) {
        als.remove(from);
        als.remove(to);
        notifyAll();
    }

}
